// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 7.10.2006 13:32:22
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Main.java

package sudoku;

import java.awt.Toolkit;
import java.io.File;

import javax.swing.JDialog;
import javax.swing.JLabel;

import sudoku.util.Config;
import sudoku.util.Language;
import sudoku.util.game.Updater;

public class Main {

  private static volatile Config config;

  public static void main(String args[]) {
    if (args.length == 0) {
      start();
    } else if (args[0].equals("update")) {
      update();
    }
  }

  private static void start() {
    try {
      (new File("Sudoku.upd.jar")).delete();
      (new File("R-Sudoku.upd.jar")).delete();
      (new File("uuenda.cmd")).delete();
      config = new Config();
      if (!(new File("Game.jar")).exists()) {
        Language language = new Language(config);
        JDialog d = new JDialog();
        d.add(new JLabel(language.getUpdater_download()));
        d.setUndecorated(true);
        d.pack();
        d.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width / 2 - d.getWidth(),
            Toolkit.getDefaultToolkit().getScreenSize().height / 2 - d.getHeight());
        d.setVisible(true);
        new Updater("jar:http://www.hot.ee/rometpiho/sudoku/Game.jar!/", "Game.jar", language);
        d.dispose();
      }
      Runtime.getRuntime().exec("java -jar Game.jar " + config.getVersioon());
    } catch (Exception e) {
      Config.log(e.getClass().toString() + ": " + e.getMessage(), e.getStackTrace());
    }
  }

  private static void update() {
    config = new Config();
    Language language = new Language(config);
    JDialog d = new JDialog();
    d.add(new JLabel(language.getUpdater_wait()));
    d.setUndecorated(true);
    d.pack();
    d.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width / 2 - d.getWidth(), Toolkit.getDefaultToolkit().getScreenSize().height
        / 2 - d.getHeight());
    d.setVisible(true);
    File orig = new File("Game.jar");
    if (config.isDebug()) {
      Config.log("starting downloading");
    }
    new Updater("jar:http://www.hot.ee/rometpiho/sudoku/Game.jar!/", "Game.uptd.jar", language);
    if (config.isDebug()) {
      Config.log("downloaded");
    }
    File uptd = new File("Game.uptd.jar");
    if (config.isDebug()) {
      Config.log("starting deleting");
    }
    boolean bool;
    for (bool = false; orig.exists() && !bool; bool = orig.delete()) {
      ;
    }
    if (bool || !orig.exists()) {
      uptd.renameTo(orig);
    } else {
      uptd.delete();
    }
    d.dispose();
    if (config.isDebug()) {
      Config.log("deleted");
    }
    try {
      Runtime.getRuntime().exec("java -jar Game.jar update");
    } catch (Exception e) {
      Config.log(e.getClass().toString() + ": " + e.getMessage(), e.getStackTrace());
    }
  }
}